package com.cbg.bus.controller;

import com.cbg.base.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.stream.Stream;

/**
 * <pre></pre>
 * <small> 2018-12-19 | chenbing </small>
 */
@RestController
@Api(value = "保险协议控制器",tags = "保险协议操作接口")
public class SafeProtocolController {
    @Value("${safe.path}")
    private String uri;

    @ApiOperation(value="展示保险信息", notes="展示保险信息")
    @GetMapping("/safe")
    public Result<?> showSafeProtocol(){
        StringBuilder sb=new StringBuilder();
        Path path = Paths.get(uri);
        try( Stream<String> fileStream = Files.lines(path)) {
            fileStream.forEach(x->{
                if(sb.length()!=0)
                    sb.append(System.lineSeparator());
                sb.append(x);
            });
        }catch (IOException e){
            e.printStackTrace();
        }
        return Result.ok(sb);
    }
}
